home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
mus
/
edit
/
AlgoRhythms.lha
/
AlgoRhythms
/
Source
/
scales.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-25
|
7KB
|
239 lines
/* Scales.c
Copyright (c) 1990,1991,1992,1993 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
208A Olde Derby Road
Norwood, MA 02062-1761
(617)769-7733
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C Amiga Compiler 6.50
**
** ABSTRACT:
**
** Scales.c creates and manages musical scales.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 26-MAR-1990
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
** 7 Dec 90 T. Janzen Procedurized filling octave-repeating scales
** 4 Jan 92 TEJ last changes for 2.0
** 2 MAR 92 TEJ Use scale_list.h
**--
*/
#include <stdlib.h> /* needed for ANSI abs () */
#include <math.h>
#include "scale_list.h"
#include "Scales.h"
#define NUMOCTAVES 7
#define BOTTOMOCT 2
static int octave_repeat_scale(const unsigned char *one_octave_scale,
int *scale,
const int scale_octave_len);
int install_scale(const int select, int *scale)
/*
** FUNCTIONAL DESCRIPTION:
** Puts a selected scale into the global current musical scale
**
** RETURN VALUE:
** description: length of scale
** data_type: int
**
** ARGUMENTS:
**
** select-
** description: number of scale to install
** data_type: int
** access: read only
**
** scale-
** description: global scale array
** data_type: pointer to int
** access: write only
**
** DESIGN:
** ROUTINE
** : IF select is in range
** : : temp_select = select
** : ELSE
** : : temp_select = 1
** : ENDIF
** : IF this is an octave-repeating scale
** : : install octave-repeating scale
** : ELSE
** : : install non-octave-repeating scale
** : ENDIF
** * RETURN scale_len
** ENDROUTINE
*/
{
const static unsigned char scale_1[SCALE_1_LEN] = SCALE_1_NOTES,
scale_2[SCALE_2_LEN] = SCALE_2_NOTES,
scale_3[SCALE_3_LEN] = SCALE_3_NOTES,
scale_4[SCALE_4_LEN] = SCALE_4_NOTES,
scale_5[SCALE_5_LEN] = SCALE_5_NOTES,
scale_6[SCALE_6_LEN] = SCALE_6_NOTES,
scale_7[SCALE_7_LEN] = SCALE_7_NOTES,
scale_8[SCALE_8_LEN] = SCALE_8_NOTES,
scale_9[SCALE_9_LEN] = SCALE_9_NOTES,
scale_10[SCALE_10_LEN] = SCALE_10_NOTES,
scale_11[SCALE_11_LEN] = SCALE_11_NOTES,
scale_12[SCALE_12_LEN] = SCALE_12_NOTES,
scale_13[SCALE_13_LEN] = SCALE_13_NOTES,
scale_14[SCALE_14_LEN] = SCALE_14_NOTES,
scale_15[SCALE_15_LEN] = SCALE_15_NOTES,
scale_16[SCALE_16_LEN] = SCALE_16_NOTES,
scale_17[SCALE_17_LEN] = SCALE_17_NOTES,
scale_18[SCALE_18_LEN] = SCALE_18_NOTES,
scale_19[SCALE_19_LEN] = SCALE_19_NOTES,
scale_20[SCALE_20_LEN] = SCALE_20_NOTES,
scale_21[SCALE_21_LEN] = SCALE_21_NOTES;
const static unsigned char *scales[C_SCALE_QTY] =
{scale_1, scale_2, scale_3, scale_4, scale_5, scale_6, scale_7,
scale_8, scale_9, scale_10, scale_11, scale_12, scale_13,
scale_14, scale_15, scale_16, scale_17, scale_18, scale_19,
scale_20, scale_21};
const static unsigned int scale_oct[C_SCALE_QTY]
= {SCALE_1_OCT, SCALE_2_OCT, SCALE_3_OCT, SCALE_4_OCT,
SCALE_5_OCT, SCALE_6_OCT, SCALE_7_OCT, SCALE_8_OCT,
SCALE_9_OCT, SCALE_10_OCT, SCALE_11_OCT, SCALE_12_OCT,
SCALE_13_OCT, SCALE_14_OCT, SCALE_15_OCT, SCALE_16_OCT,
SCALE_17_OCT, SCALE_18_OCT, SCALE_19_OCT, SCALE_20_OCT,
SCALE_21_OCT},
scale_lens[C_SCALE_QTY]
= {SCALE_1_LEN, SCALE_2_LEN, SCALE_3_LEN, SCALE_4_LEN,
SCALE_5_LEN, SCALE_6_LEN, SCALE_7_LEN, SCALE_8_LEN,
SCALE_9_LEN, SCALE_10_LEN, SCALE_11_LEN, SCALE_12_LEN,
SCALE_13_LEN, SCALE_14_LEN, SCALE_15_LEN, SCALE_16_LEN,
SCALE_17_LEN, SCALE_18_LEN, SCALE_19_LEN, SCALE_20_LEN,
SCALE_21_LEN};
auto int index,
scale_len,
temp_select;
if ((select > 0) && (select <= C_SCALE_QTY))
{
temp_select = select - 1;
}
else
{
temp_select = 0;
}
if (scale_oct[temp_select])
{
scale_len = octave_repeat_scale(scales[temp_select], scale,
scale_lens[temp_select]);
}
else
{
for (index = 0; index < scale_lens[temp_select]; index++)
{
scale[index] = (int)scales[temp_select][index];
}
scale_len = scale_lens[temp_select];
}
return scale_len;
}
void transpose_scale( const int transpose, int *scale,
const int range)
/*
** FUNCTIONAL DESCRIPTION:
**
** ARGUMENTS:
**
** transpose-
** description: interval in semitones to transpose the scale
** data_type: int
** access: read only
**
** scale-
** description: the global scale array
** data_type: pointer to int
** access: write only
**
** range-
** description: length of scale
** data_type: int
** access: read only
**
** DESIGN:
** ROUTINE
** : IF transposition magnitude is under 12
** : : FOR length of scale
** : : : transpose each scale element
** : : ENDFOR
** ENDROUTINE
*/
{
register int i;
if (abs(transpose) < 12)
{
for (i = 0; i < range; i++)
{
scale[i] = scale[i] + transpose;
}
}
return;
}
static int octave_repeat_scale(const unsigned char *one_octave_scale,
int *scale,
const int scale_octave_len)
/*
** FUNCTIONAL DESCRIPTION:
**
** RETURN VALUE:
** description:
** data_type:
**
** ARGUMENTS:
**
** one_octave_scale-
** description: one octave of the selected scale
** data_type: pointer to char
** access: read only
**
** scale-
** description: global scale
** data_type: pointer to int
** access: write only
**
** scale_octave_len-
** description: length of one octave of scale
** data_type: int
** access: read only
**
** DESIGN:
*/
{
auto int oct,
i;
for (oct = 0; oct < NUMOCTAVES; oct++)
{
for (i = 0; i < scale_octave_len; i++)
{
scale[i + (oct * scale_octave_len)]
= (int)one_octave_scale[i] + ((oct + BOTTOMOCT) * 12);
}
}
return (NUMOCTAVES * scale_octave_len);
}